//package com.micro.glszh.stat.config;
//
//import cn.hutool.core.collection.CollUtil;
//import com.xbzl.common.web.properties.SwaggerProperties;
//import io.swagger.annotations.Api;
//import lombok.RequiredArgsConstructor;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Import;
//import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
//import springfox.documentation.builders.OAuthBuilder;
//import springfox.documentation.builders.PathSelectors;
//import springfox.documentation.builders.RequestHandlerSelectors;
//import springfox.documentation.service.*;
//import springfox.documentation.spi.DocumentationType;
//import springfox.documentation.spi.service.contexts.SecurityContext;
//import springfox.documentation.spring.web.plugins.Docket;
//import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
//
//import java.util.ArrayList;
//import java.util.List;
//
//
///**
// * @author gaopengfei
// * @version 1.0
// * @description: swagger 类核心配置
// * @date 2023/3/2 10:19
// */
//@RequiredArgsConstructor
//@Configuration
//@Import(BeanValidatorPluginsConfiguration.class)
//@EnableSwagger2WebMvc
//public class SwaggerConfig {
//
//    private final SwaggerProperties swaggerProperties;
//
//    @Bean
//    public Docket docket() {
//        //schema
//        List<GrantType> grantTypes = new ArrayList<>();
//        //密码模式
//        ResourceOwnerPasswordCredentialsGrant resourceOwnerPasswordCredentialsGrant = new ResourceOwnerPasswordCredentialsGrant(swaggerProperties.getPasswordTokenUrl());
//        grantTypes.add(resourceOwnerPasswordCredentialsGrant);
//        OAuth oAuth = new OAuthBuilder().name("oauth2")
//                .grantTypes(grantTypes).build();
//        //context
//        //scope方位
//        List<AuthorizationScope> scopes = new ArrayList<>();
//        scopes.add(new AuthorizationScope("read", "read  resources"));
//        scopes.add(new AuthorizationScope("write", "write resources"));
//        scopes.add(new AuthorizationScope("reads", "read all resources"));
//        scopes.add(new AuthorizationScope("writes", "write all resources"));
//
//        SecurityReference securityReference = new SecurityReference("oauth2", scopes.toArray(new AuthorizationScope[]{}));
//        SecurityContext securityContext = new SecurityContext(CollUtil.newArrayList(securityReference), PathSelectors.ant("/**"));
//        //schemas
//        List<SecurityScheme> securitySchemes = CollUtil.newArrayList(oAuth);
//        //securyContext
//        List<SecurityContext> securityContexts = CollUtil.newArrayList(securityContext);
//        return new Docket(DocumentationType.SWAGGER_2)
//                .select()
//                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
//                .paths(PathSelectors.any())
//                .build()
//                .securityContexts(securityContexts)
//                .securitySchemes(securitySchemes)
//                .apiInfo(apiInfo())
//                .enable(swaggerProperties.getEnabled());
//    }
//
//    private ApiInfo apiInfo() {
//        /*作者信息*/
//        Contact contact = new Contact(swaggerProperties.getContact().getName(), swaggerProperties.getContact().getUrl(), swaggerProperties.getContact().getEmail());
//        return new ApiInfo(
//                swaggerProperties.getApiInfo().getTitle(),
//                swaggerProperties.getApiInfo().getDescription(),
//                swaggerProperties.getApiInfo().getVersion(),
//                swaggerProperties.getApiInfo().getTermsOfServiceUrl(),
//                contact,
//                swaggerProperties.getApiInfo().getLicense(),
//                swaggerProperties.getApiInfo().getLicenseUrl(),
//                new ArrayList()
//        );
//    }
//
//}
